import { _decorator, BoxCollider2D, Button, CircleCollider2D, Color, Component, Contact2DType, Director, director, find, Graphics, instantiate, Label, Layers, Layout, Node, ParticleSystem2D, Prefab, ProgressBar, resources, Skeleton, sp, Sprite, SpriteFrame, TERRAIN_SOUTH_INDEX, tween, v2, v3, Vec2 } from 'cc';
import { tagEnum } from './Enum';
import { GreenBall } from './GreenBall';
import { convertNumber, getDistance, randomNum } from './utils/utils';
import { Fish } from './Fish';
import { PoolMgr } from './utils/PoolMgr';
import { TouchMove } from './TouchMove';
import { Prop } from './Prop';
import { UserInfo } from './UserInfo';
import { AudioMgr } from './utils/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('GameMgr')
export class GameMgr extends Component {

    static ins: GameMgr;
    @property(Prefab)
    greenBallPre: Prefab
    @property(Prefab)
    greenBall1Pre: Prefab
    @property(Node)
    player: Node;
    @property(ProgressBar)
    expPro: ProgressBar;
    @property(Node)
    greenBallRoot: Node;
    @property(Node)
    otherFishRoot: Node;
    @property(Node)
    revivePanel: Node;
    @property(Node)
    failPanel: Node;
    @property(Prefab)
    widowTipPre: Prefab;
    @property(Node)
    finallyFishPanel: Node;
    @property(Node)
    propShenkunBtn: Node;
    @property(Node)
    setPanel: Node;
    @property(Prefab)
    propPre: Prefab;
    @property(Label)
    volumeNumLabel: Label;
    @property(Node)
    propRoot: Node;
    @property(Prefab)
    gearEffect: Prefab;
    @property(Prefab)
    screenEffect: Prefab;
    @property(Label)
    shenkunTimeLabel:Label;

    currSelfFish = [0, 0];

    mapBoundary = v2(2300, 2500);

    isCanReviveTotalNum;//可以复活几次

    isGameIng = true;

    private isWuDi = false;//是否是无敌状态
    get IsWuDi() {
        return this.isWuDi;
    }
    set IsWuDi(value) {
        this.isWuDi = value;

        if (value == true) {
            this.player.children[0].getChildByName("shield").active = true;
        }
        else {
            this.player.children[0].getChildByName("shield").active = false;
        }
    }

    isUseFrozenSkillIng = false;//玩家是否正在使用冻结技能
    isUseSpeedUpSkillIng = false;//玩家是否正在使用加速技能


    private exp = 0;

    get Exp() {
        return this.exp;
    }
    set Exp(value) {
        if (value >= this.maxExp(this.currSelfFish)) {
            this.finshLevelUp();
            console.log("升级");
            this.exp = value;

            return;
        }
        this.exp = value;
        this.expPro.progress = value / this.maxExp(this.currSelfFish);
        this.expPro.node.getChildByName("Label").getComponent(Label).string = `${convertNumber(value)}/${convertNumber(this.maxExp(this.currSelfFish))}`

        GameMgr.ins.volumeNumLabel.string = this.getFishName(this.currSelfFish[0]) + ":" + convertNumber(this.exp);
    }

    maxExp(_currSelfFish) {
        // return (this.currSelfFish[0]+1)*20+(this.currSelfFish[1]+1)*10
        return Math.pow(2, (_currSelfFish[0] + 1) * 3 + _currSelfFish[1])

        //2^3,2^4,2^5
    }

    // @property(Graphics)
    // graphics: Graphics = null; // 绑定的 Graphics 组件

    // private trailPoints: Vec2[] = []; // 存储轨迹点
    // private maxTrailLength: number = 20; // 最大轨迹点数量


    // update(dt: number) {
    //     // 记录当前物体的位置
    //     this.trailPoints.push(v2(this.player.position.x,this.player.position.y));

    //     // 如果轨迹点数量超过最大值，移除最旧的点
    //     if (this.trailPoints.length > this.maxTrailLength) {
    //         this.trailPoints.shift();
    //     }

    //     // 绘制拖尾
    //     this.graphics.clear();
    //     for (let i = 0; i < this.trailPoints.length - 1; i++) {
    //         const start = this.trailPoints[i];
    //         const end = this.trailPoints[i + 1];
    //         const alpha = i / this.trailPoints.length; // 计算透明度
    //         this.graphics.strokeColor = new Color(255, 0, 0, 255 * alpha);
    //         this.graphics.moveTo(start.x, start.y);
    //         this.graphics.lineTo(end.x, end.y);
    //         this.graphics.stroke();
    //     }
    // }


    minExp(_currSelfFish) {
        // return (this.currSelfFish[0]+1)*20+(this.currSelfFish[1]+1)*10
        let count = (_currSelfFish[0] + 1) * 3 + _currSelfFish[1];
        let res;
        if (count == 3) {
            res = 0;
        }
        else {
            res = Math.pow(2, (count - 1))
        }
        return res

        //2^3,2^4,2^5
    }

    //计数单位，判断当前自己的等级,从3开始 3,4,5,6以此类推
    get jishu() {
        return (this.currSelfFish[0] + 1) * 3 + this.currSelfFish[1]
    }

    gameSet() {
        this.isCanReviveTotalNum = 2;
        this.isGameIng = true;
        this.volumeNumLabel.string = "鲽鱼:0"
    }
    protected onLoad(): void {
        GameMgr.ins = this;
        this.initCreateGreenBall();

        this.currSelfFish = [0, 0];
        this.Exp = 0;
    }

    protected start(): void {
        // this.graphics.clear();

        let skeComp = this.player.children[0].getChildByName("sp").getComponent(sp.Skeleton)
        skeComp.setCompleteListener((trackEntry) => {
            let name = trackEntry.animation ? trackEntry.animation.name : '';
            if (name === "eat") {
                skeComp.setAnimation(0, "idle", true)
            }
        });
        this.player.children[0].getComponent(BoxCollider2D).on(Contact2DType.BEGIN_CONTACT, this.beginTouch);
        this.player.children[0].getChildByName("rangeCod").getComponent(CircleCollider2D).on(Contact2DType.BEGIN_CONTACT, this.rangCodBeginTouch);
        this.initEnvironment();
        this.gameSet();

        if (UserInfo.isAudioBgm) {
            AudioMgr.ins.play("audio/bgm");
        }
        else{
            AudioMgr.ins.stop();
        }

    }

    initEnvironment() {
        this.createEnvironmentGameFishNotNearlySelf(0, 4);
        this.createEnvironmentGameFishNotNearlySelf(0, 4);
        this.createEnvironmentGameFishNotNearlySelf(0, 4);
        this.createEnvironmentGameFishNotNearlySelf(0, 4);
        this.createEnvironmentGameFishNotNearlySelf(0, 4);
        this.createEnvironmentGameFishNotNearlySelf(0, 4);
        this.createEnvironmentGameFishNotNearlySelf(0, 2);
        this.createEnvironmentGameFishNotNearlySelf(0, 2);
        this.createEnvironmentGameFishNotNearlySelf(0, 2);
        this.createEnvironmentGameFishNotNearlySelf(0, 8);
        this.createEnvironmentGameFishNotNearlySelf(1, 6);
        this.createEnvironmentGameFishNotNearlySelf(1, 6);
        this.createOnePropInEnvironment(randomNum(0, 1));
        this.createOnePropInEnvironment(randomNum(0, 1));
    }


    beginTouch(self, other) {
        director.once(Director.EVENT_AFTER_PHYSICS, () => {
            if (other.tag == tagEnum.prop) {
                if (other.node.getComponent(Prop)) {
                    let type = other.node.getComponent(Prop).propType;
                    if (type == 0) {//冻结道具
                        if (GameMgr.ins.isUseFrozenSkillIng == false) {
                            GameMgr.ins.isUseFrozenSkillIng = true;
                            other.node.destroy();
                            let pre = instantiate(GameMgr.ins.gearEffect);
                            pre.setParent(find("Canvas"));
                            let pre1 = instantiate(GameMgr.ins.screenEffect);
                            pre1.setParent(find("Canvas"));
                            for (let i = 0; i < GameMgr.ins.otherFishRoot.children.length; i++) {
                                GameMgr.ins.otherFishRoot.children[i].getComponent(Fish).IsFrozenIng = true;
                            }

                            setTimeout(() => {
                                pre.destroy();
                            }, 1000);
                            setTimeout(() => {
                                GameMgr.ins.isUseFrozenSkillIng = false;
                                pre1.destroy();
                                for (let i = 0; i < GameMgr.ins.otherFishRoot.children.length; i++) {
                                    GameMgr.ins.otherFishRoot.children[i].getComponent(Fish).IsFrozenIng = false;
                                }
                            }, 10000)
                        }

                    }
                    else if (type == 1) {//加速技能
                        if (GameMgr.ins.isUseSpeedUpSkillIng == false) {
                            GameMgr.ins.isUseSpeedUpSkillIng = true;
                            other.node.destroy();
                            GameMgr.ins.player.children[0].getChildByName("waveEffect").getComponent(ParticleSystem2D).resetSystem();
                            TouchMove.ins.moveSpeed += 3

                            setTimeout(() => {
                                GameMgr.ins.player.children[0].getChildByName("waveEffect").getComponent(ParticleSystem2D).stopSystem();
                                GameMgr.ins.isUseSpeedUpSkillIng = false;
                                TouchMove.ins.moveSpeed -= 3

                            }, 10000)
                        }
                    }

                    GameMgr.ins.createOnePropInEnvironment(randomNum(0, 1));
                }

            }
            if (other.tag == tagEnum.greenBall) {
                other.node.getComponent(GreenBall).eated();
                GameMgr.ins.Exp += Math.round(GameMgr.ins.jishu / 3);
            }

            if (other.tag == tagEnum.greenBall1) {
                other.node.getComponent(GreenBall).eated();
                GameMgr.ins.Exp += Math.round(GameMgr.ins.jishu / 3) * 3;
            }

            if (other.tag >= 100) {//如果碰撞其他鱼类
                console.log("碰撞其他鱼类")

                if (other.node.getComponent(Fish).exp >= GameMgr.ins.Exp) {
                    if (GameMgr.ins.IsWuDi == false) {
                        GameMgr.ins.gameOver();
                    }
                }
                else {//吃
                    AudioMgr.ins.playOneShot("audio/fishEat",0.7);
                    self.node.getChildByName("sp").getComponent(sp.Skeleton).setAnimation(0, "eat", false);
                    self.node.getChildByName("eatEffect").getComponent(sp.Skeleton).setAnimation(0, "animation", false);
                    let getExp = Math.round(other.node.getComponent(Fish).exp / 3);
                    if (getExp < 3) {
                        getExp = 3;
                    }
                    GameMgr.ins.Exp += getExp;

                    other.node.destroy();

                    //少了一个鱼就再生成一个鱼
                    let fishType = randomNum(GameMgr.ins.currSelfFish[0] - 1, GameMgr.ins.currSelfFish[0] + 1);
                    if (fishType < 0) {
                        fishType = 0
                    }
                    if (fishType > 8) {
                        fishType = 8;
                    }
                    GameMgr.ins.createEnvironmentGameFishNotNearlySelf(fishType, 1);

                }
            }
        })
    }

    rangCodBeginTouch(self, other) {

        if (other.node.parent.name == "player") {
            return;
        }
        director.once(Director.EVENT_AFTER_PHYSICS, () => {
            if (other.tag >= 100) {//如果检测到其他鱼类
                if (other.node.getComponent(Fish)) {
                    let comp = other.node.getComponent(Fish);
                    if (comp.exp >= GameMgr.ins.Exp) {
                        if (GameMgr.ins.IsWuDi == false) {
                            comp.meetPlayerPursue();
                        }
                    }
                    else {
                        comp.meetPlayerRunAway();
                    }

                }


            }
        })
    }

    initCreateGreenBall() {
        for (let i = 0; i < 361; i++) {
            let randcount = randomNum(0, 21);
            if (randcount == 21) {
                // let pre = instantiate(this.greenBall1Pre);
                let pre = PoolMgr.getIns().poolGet("greenBall1");
                pre.setParent(this.greenBallRoot);
            }
            else {
                // let pre = instantiate(this.greenBallPre);
                let pre = PoolMgr.getIns().poolGet("greenBall");
                pre.setParent(this.greenBallRoot);
            }

        }
    }

    finshLevelUp() {
        if (this.currSelfFish[0] == 8 && this.currSelfFish[1] == 2) {
            if (this.isGameIng == true) {
                console.log("合成最高级游戏结束");
            AudioMgr.ins.playOneShot("audio/dragon",0.7);
            
                this.isGameIng = false;
                this.finallyFishPanel.active = true;
                let skeComp = this.finallyFishPanel.getChildByName("sp").getComponent(sp.Skeleton);

                skeComp.setAnimation(0, "appearance", false);

                skeComp.setCompleteListener((trackEntry) => {
                    let name = trackEntry.animation ? trackEntry.animation.name : '';
                    if (name === "appearance") {
                        skeComp.setAnimation(0, "idle", true);
                        this.finallyFishPanel.getChildByName("bg").on(Node.EventType.TOUCH_START, () => {
                            this.finallyFishPanel.active = false;
                            this.openFailPanel();
                        })
                    }
                });
            }

            return;
        }

        if (this.currSelfFish[1] == 2) {
            this.currSelfFish = [this.currSelfFish[0] + 1, 0];
        }
        else {
            this.currSelfFish[1] += 1;
        }

        this.player.removeAllChildren();

        resources.load(`prefabs/fish/${this.currSelfFish[0]}`, Prefab, (err, res) => {
            let pre = instantiate(res);
            pre.setParent(this.player);

            let preScale = pre.scale;
            if (this.currSelfFish[1] == 1) {
                pre.scale = v3(preScale.x + 0.15, preScale.y + 0.15, 1);
            }
            else if (this.currSelfFish[1] == 2) {
                pre.scale = v3(preScale.x + 0.3, preScale.y + 0.3, 1);
            }

            this.expPro.progress = this.exp / this.maxExp(this.currSelfFish);
            this.expPro.node.getChildByName("Label").getComponent(Label).string = `${this.exp}/${this.maxExp(this.currSelfFish)}`

            this.volumeNumLabel.string = this.getFishName(this.currSelfFish[0]) + ":" + convertNumber(this.exp);
            this.player.children[0].getChildByName("volumeNumLabel").active = false;
            this.player.children[0].getChildByName("fishUpEffect").getComponent(sp.Skeleton).setAnimation(0, "animation", false);

            if (this.IsWuDi) {
                this.player.children[0].getChildByName("shield").active = true;
            }
            if (this.isUseSpeedUpSkillIng) {
                this.scheduleOnce(() => {
                    this.player.children[0].getChildByName("waveEffect").getComponent(ParticleSystem2D).resetSystem();
                }, 0.7)
            }

            this.player.children[0].getComponent(BoxCollider2D).on(Contact2DType.BEGIN_CONTACT, this.beginTouch);
            this.player.children[0].getChildByName("rangeCod").getComponent(CircleCollider2D).on(Contact2DType.BEGIN_CONTACT, this.rangCodBeginTouch);

            let skeComp = this.player.children[0].getChildByName("sp").getComponent(sp.Skeleton)
            skeComp.setCompleteListener((trackEntry) => {
                let name = trackEntry.animation ? trackEntry.animation.name : '';
                if (name === "eat") {
                    skeComp.setAnimation(0, "idle", true)
                }
            });

        })
    }

    getFishName(id) {
        let str = "";
        switch (id) {
            case 0:
                str = "鲽鱼"
                break;
            case 1:
                str = "鲷鱼"
                break;
            case 2:
                str = "石斑鱼"
                break;
            case 3:
                str = "突角鼻鱼"
                break;
            case 4:
                str = "海鲈鱼"
                break;
            case 5:
                str = "矛尾鱼"
                break;
            case 6:
                str = "安康鱼"
                break;
            case 7:
                str = "突吻鲸"
                break;
            case 8:
                str = "鲨鱼"
                break;
            case 9:
                str = "蓝色巨型鲨鱼"
                break;
        }

        return str
    }

    createEnvironmentGameFish(type, num) {
        resources.load(`prefabs/fish/${type}`, Prefab, (err, res) => {
            for (let i = 0; i < num; i++) {
                let pre = instantiate(res);
                pre.getChildByName("rangeCod").active = false;
                pre.setParent(this.otherFishRoot);
                pre.setPosition(randomNum(-this.mapBoundary.x + 500, this.mapBoundary.x - 500), randomNum(-this.mapBoundary.y + 500, this.mapBoundary.y - 500));
                pre.addComponent(Fish);
                let fishTypeArr = [type, randomNum(0, 2)]
                pre.getComponent(Fish).init(fishTypeArr, randomNum(this.minExp(fishTypeArr), this.maxExp(fishTypeArr)))
            }

        })
    }

    //生成其他鱼类
    createEnvironmentGameFishNotNearlySelf(type, num) {
        console.log('补充鱼类:', type)
        let pos = null;
        while (pos == null) {
            pos = v2(randomNum(-this.mapBoundary.x + 500, this.mapBoundary.x - 500), randomNum(-this.mapBoundary.y + 500, this.mapBoundary.y - 500));
            if (getDistance(this.player.position.x, this.player.position.y, pos.x, pos.y) < 700) {
                pos = null;
            }

        }
        resources.load(`prefabs/fish/${type}`, Prefab, (err, res) => {
            for (let i = 0; i < num; i++) {
                let pre = instantiate(res);
                pre.getChildByName("rangeCod").active = false;
                pre.setParent(this.otherFishRoot);
                pre.setPosition(pos.x, pos.y);
                pre.addComponent(Fish);
                let fishTypeArr = [type, randomNum(0, 2)];
                pre.getComponent(Fish).init(fishTypeArr, randomNum(this.minExp(fishTypeArr), this.maxExp(fishTypeArr)))
            }

        })
    }

    gameOver() {
        if (this.isGameIng == true) {
            console.log("游戏结束");
            AudioMgr.ins.playOneShot("audio/lose",0.7);

            this.isGameIng = false;
            if (this.isCanReviveTotalNum > 0) {
                this.revivePanel.active = true;
                this.revivePanel.getChildByName("yesBtn").getChildByName("reviveNumLabel").getComponent(Label).string = "剩余复活次数：" + this.isCanReviveTotalNum;

                this.revivePanel.getChildByName("liangbeij").getChildByName("fishRoot").removeAllChildren();
                resources.load(`prefabs/fish/${this.currSelfFish[0]}`, Prefab, (err, res) => {
                    let pre = instantiate(res);
                    pre.setParent(this.revivePanel.getChildByName("liangbeij").getChildByName("fishRoot"));
                    pre.layer = 0;
                    pre.layer = Layers.Enum.UI_3D;
                    for (let i = 0; i < pre.children.length; i++) {
                        pre.children[i].layer = 0;
                        pre.children[i].layer = Layers.Enum.UI_3D;
                    }
                    pre.getChildByName("rangeCod").active = false;
                    pre.getChildByName("volumeNumLabel").active = false;
                })
            }
            else {
                this.openFailPanel();
            }
        }

    }

    onclickReviveBtn() {
        AudioMgr.ins.playOneShot("audio/btn",0.7);

        if (this.isCanReviveTotalNum > 0) {

            this.revivePanel.active = false;
            this.isGameIng = true;
            this.isCanReviveTotalNum -= 1;

            this.otherFishRoot.removeAllChildren();
            this.propRoot.removeAllChildren();
            this.initEnvironment();

        }
        else {
            this.createWidowTip("复活次数用完了")

        }
    }

    onclickCancelReviveBtn() {
        AudioMgr.ins.playOneShot("audio/btn",0.7);

        this.revivePanel.active = false;
        this.openFailPanel();

    }

    openFailPanel() {
        this.failPanel.active = true;
        let num = 1;
        num = (this.jishu) * 3;
        if (this.currSelfFish[0] == 8 && this.currSelfFish[1] == 2) {
            num = 99
        }
        this.failPanel.getChildByName("beatPlayerLabel").getComponent(Label).string = `击败了全球${num}%的玩家`;

    }

    onclickReturnHomeBtn() {
        AudioMgr.ins.playOneShot("audio/btn",0.7);

        director.loadScene("home");
    }

    createWidowTip(str) {
        let pre = instantiate(this.widowTipPre);
        pre.setParent(find("Canvas"));
        pre.setPosition(0, -50);
        pre.getChildByName("Label").getComponent(Label).string = str;
        tween(pre)
            .to(0.5, { position: v3(0, 0, 0) })
            .delay(2)
            .call(() => {
                pre.destroy();
            })
            .start()
    }

    onclickPropJInhuaBtn() {
        let getExp = this.maxExp(this.currSelfFish) - this.Exp;

        this.Exp += getExp;
    }

    onclickPropShenkunBtn() {
        if (this.IsWuDi == true) {
            this.createWidowTip("正在无敌模式");
            return;
        }
        else {
            this.propShenkunBtn.getComponent(Button).enabled = false;
            this.propShenkunBtn.getComponent(sp.Skeleton).color = new Color().fromHEX("#929292");

            this.IsWuDi = true;
            this.shenkunTimeLabel.node.active = true;
            this.shenkunTimeLabel.string = 20 + "";
            TouchMove.ins.moveSpeed += 8;

            let timeCount = 20;
            this.schedule(() => {
                timeCount -= 1;
                this.shenkunTimeLabel.string = timeCount + "";
                if (timeCount == 0) {
                    this.propShenkunBtn.getComponent(Button).enabled = true;
                    this.propShenkunBtn.getComponent(sp.Skeleton).color = Color.WHITE;

                    this.shenkunTimeLabel.node.active = false;
                    this.IsWuDi = false;
                    TouchMove.ins.moveSpeed -= 8;

                }
            }, 1, 19)
        }
    }

    onclickSetBtn() {
        AudioMgr.ins.playOneShot("audio/btn",0.7);

        this.isGameIng = false;
        this.setPanel.active = true;
        this.renewAudioUI();
    }

    onclickSetPanelContinueGameBtn() {
        AudioMgr.ins.playOneShot("audio/btn",0.7);

        this.isGameIng = true;
        this.setPanel.active = false;
    }

    createOnePropInEnvironment(type) {
        let pos = null;
        while (pos == null) {
            pos = v2(randomNum(-this.mapBoundary.x + 500, this.mapBoundary.x - 500), randomNum(-this.mapBoundary.y + 500, this.mapBoundary.y - 500));
            if (getDistance(this.player.position.x, this.player.position.y, pos.x, pos.y) < 700) {
                pos = null;
            }

        }

        let pre = instantiate(this.propPre);
        pre.setParent(this.propRoot);
        console.log("pos", pos)
        pre.setPosition(pos.x, pos.y);

        // pre.setPosition(v3(300,300,0));
        pre.getComponent(Prop).init(type);

    }

    onclickSetPanelaudioEffectBtn() {
        if (UserInfo.isAudioEffect) {
            UserInfo.isAudioEffect = false;
        }
        else {
            UserInfo.isAudioEffect = true;
        }

        this.renewAudioUI();
    }
    onclickSetPanelBgmBtn() {
        if (UserInfo.isAudioBgm) {
            UserInfo.isAudioBgm = false;
            AudioMgr.ins.stop();
        }
        else {
            UserInfo.isAudioBgm = true;
            AudioMgr.ins.play("audio/bgm");
        }
        this.renewAudioUI();

    }


    renewAudioUI() {
        if (UserInfo.isAudioBgm) {
            resources.load("audioImg/starOn/spriteFrame", SpriteFrame, (err, res) => {
                this.setPanel.getChildByName("bgmBtn").getChildByName("star").getComponent(Sprite).spriteFrame = res;

            })
            resources.load("audioImg/itemBgOn/spriteFrame", SpriteFrame, (err, res) => {
                this.setPanel.getChildByName("bgmBtn").getChildByName("bg").getComponent(Sprite).spriteFrame = res;

            })
            this.setPanel.getChildByName("bgmBtn").getChildByName("star").setPosition(50, 0);
        }
        else {
            resources.load("audioImg/starOff/spriteFrame", SpriteFrame, (err, res) => {
                this.setPanel.getChildByName("bgmBtn").getChildByName("star").getComponent(Sprite).spriteFrame = res;

            })
            resources.load("audioImg/itemBgOff/spriteFrame", SpriteFrame, (err, res) => {
                this.setPanel.getChildByName("bgmBtn").getChildByName("bg").getComponent(Sprite).spriteFrame = res;

            })
            this.setPanel.getChildByName("bgmBtn").getChildByName("star").setPosition(-50, 0);

        }

        if (UserInfo.isAudioEffect) {
            resources.load("audioImg/starOn/spriteFrame", SpriteFrame, (err, res) => {
                this.setPanel.getChildByName("effectBtn").getChildByName("star").getComponent(Sprite).spriteFrame = res;

            })
            resources.load("audioImg/itemBgOn/spriteFrame", SpriteFrame, (err, res) => {
                this.setPanel.getChildByName("effectBtn").getChildByName("bg").getComponent(Sprite).spriteFrame = res;

            })
            this.setPanel.getChildByName("effectBtn").getChildByName("star").setPosition(50, 0);

        }
        else {
            resources.load("audioImg/starOff/spriteFrame", SpriteFrame, (err, res) => {
                this.setPanel.getChildByName("effectBtn").getChildByName("star").getComponent(Sprite).spriteFrame = res;

            })
            resources.load("audioImg/itemBgOff/spriteFrame", SpriteFrame, (err, res) => {
                this.setPanel.getChildByName("effectBtn").getChildByName("bg").getComponent(Sprite).spriteFrame = res;

            })
            this.setPanel.getChildByName("effectBtn").getChildByName("star").setPosition(-50, 0);

        }
    }




}


